package com.dxy.hms.listener;

import cn.hutool.core.collection.CollUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class ApplicationRunListener {

	@Autowired(required = false)
	private List<AppInitHandler> appInitHandlerList;

	@EventListener
	public void appStartEvent(ApplicationReadyEvent event) {
		log.info("应用启动...");
		if (CollUtil.isNotEmpty(appInitHandlerList)){
			appInitHandlerList.forEach(AppInitHandler::execute);
		}
	}

	@EventListener
	public void appCloseEvent(ContextClosedEvent event) {
		log.info("应用关闭...");
	}
}
